﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using HellCook.Model;
using HellCook.WinApp_WPF.IngredientManager.IngredientFunctionality;

namespace HellCook.WinApp_WPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();


            ActualizarListasDeCompras();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            IngredientManager.IngredientManager IngredienteManager = new IngredientManager.IngredientManager();
            IngredienteManager.ShowDialog();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            RecipeManager.RecipeManager RecipeManager = new RecipeManager.RecipeManager();
            RecipeManager.ShowDialog();
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void MenuItemNewIngredient(object sender, RoutedEventArgs e)
        {
            AddNewIngredient A = new AddNewIngredient();
            A.ShowDialog();
        }

        private void MenuItemSeachIngredient(object sender, RoutedEventArgs e)
        {
            SearchIngredient A = new SearchIngredient();
            A.ShowDialog();
        }

        private void newRecipe(object sender, RoutedEventArgs e)
        {
            AddNewRecipe A = new AddNewRecipe();
            A.ShowDialog();
        }

        private void MenuSearchRecipe(object sender, RoutedEventArgs e)
        {
            SearchIngredient A = new SearchIngredient();
            A.ShowDialog();
        }

        private void Boton_MenuSemanal_Click(object sender, RoutedEventArgs e)
        {
            HellCook.WinApp_WPF.Menu.MenuSemanal Menu_Semanal = new Menu.MenuSemanal();
            if (Menu_Semanal.Ejecutar == true)
            {
                Menu_Semanal.ShowDialog();
            }
            else
            {
                Menu_Semanal.Close();
            }
        }

        private void button1_Click_1(object sender, RoutedEventArgs e)
        {
            string FechaDeHoy = DateTime.Today.DayOfWeek.ToString();
            Menu.MenuSemanal Menu = new Menu.MenuSemanal(FechaDeHoy);
            if (Menu.Ejecutar == true)
            {
                Menu.ShowDialog();
            }
            else
            {
                Menu.Close();
            }
        }

        private void Button_ImprimirListaComprasDiarias_Click(object sender, RoutedEventArgs e)
        {
            //PrintDialog printDlg = new PrintDialog();
            //if (printDlg.ShowDialog() == true)
            //{
            //    printDlg.PrintVisual(this.ListaIngredientes_Diario, "Lista de compras diaria.");
            //}


            System.Windows.Controls.PrintDialog Printdlg = new System.Windows.Controls.PrintDialog();
            if ((bool)Printdlg.ShowDialog().GetValueOrDefault())
            {
                Size pageSize = new Size(Printdlg.PrintableAreaWidth, Printdlg.PrintableAreaHeight);
                // sizing of the element.
                this.ListaIngredientes_Diario.Measure(pageSize);
                this.ListaIngredientes_Diario.Arrange(new Rect(5, 5, pageSize.Width, pageSize.Height));
                Printdlg.PrintVisual(this.ListaIngredientes_Diario, Title);
            }
        }

        private void Button_ImprimirListaComprasMensual_Click(object sender, RoutedEventArgs e)
        {
            //PrintDialog printDlg = new PrintDialog();
            //if (printDlg.ShowDialog() == true)
            //{
            //    printDlg.PrintVisual(this.ListaIngredientes_Diario, "Lista de compras diaria.");
            //}


            System.Windows.Controls.PrintDialog Printdlg = new System.Windows.Controls.PrintDialog();
            if ((bool)Printdlg.ShowDialog().GetValueOrDefault())
            {
                Size pageSize = new Size(Printdlg.PrintableAreaWidth, Printdlg.PrintableAreaHeight);
                // sizing of the element.
                this.ListaIngredientes_Mensual.Measure(pageSize);
                this.ListaIngredientes_Mensual.Arrange(new Rect(5, 5, pageSize.Width, pageSize.Height));
                Printdlg.PrintVisual(this.ListaIngredientes_Mensual, Title);
            }
        }

        private void Button_ImprimirListaComprasSemanal_Click(object sender, RoutedEventArgs e)
        {
            //PrintDialog printDlg = new PrintDialog();
            //if (printDlg.ShowDialog() == true)
            //{
            //    printDlg.PrintVisual(this.ListaIngredientes_Diario, "Lista de compras diaria.");
            //}


            System.Windows.Controls.PrintDialog Printdlg = new System.Windows.Controls.PrintDialog();
            if ((bool)Printdlg.ShowDialog().GetValueOrDefault())
            {
                Size pageSize = new Size(Printdlg.PrintableAreaWidth, Printdlg.PrintableAreaHeight);
                // sizing of the element.
                this.ListaIngredientes_Semanal.Measure(pageSize);
                this.ListaIngredientes_Semanal.Arrange(new Rect(5, 5, pageSize.Width, pageSize.Height));
                Printdlg.PrintVisual(this.ListaIngredientes_Semanal, Title);
            }
        }

        private void ListaIngredientes_Diario_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.ListaIngredientes_Diario.SelectedIndex >= 0)
            {
                ListaDeCompras ListaDeCompra = (ListaDeCompras)this.ListaIngredientes_Diario.SelectedItem;
                Ingrediente Modificar = HellCook.Business.Ingrediente_Buscador.ObtenerIngredientePorGodigo(ListaDeCompra.Codigo_Ingrediente.ToString());
                Ingrediente_Administrador.IngredientFunctionality.ModificarIngrediente modificar = new Ingrediente_Administrador.IngredientFunctionality.ModificarIngrediente(Modificar);
                modificar.ShowDialog();

                this.ListaIngredientes_Diario.SelectedIndex = -1;
            }
        }

        private void ListaIngredientes_Semanal_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.ListaIngredientes_Semanal.SelectedIndex >= 0)
            {
                ListaDeCompras ListaDeCompra = (ListaDeCompras)this.ListaIngredientes_Semanal.SelectedItem;
                Ingrediente Modificar = HellCook.Business.Ingrediente_Buscador.ObtenerIngredientePorGodigo(ListaDeCompra.Codigo_Ingrediente.ToString());
                Ingrediente_Administrador.IngredientFunctionality.ModificarIngrediente modificar = new Ingrediente_Administrador.IngredientFunctionality.ModificarIngrediente(Modificar);
                modificar.ShowDialog();

                this.ListaIngredientes_Semanal.SelectedIndex = -1;
            }
        }

        private void ListaIngredientes_Mensual_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.ListaIngredientes_Mensual.SelectedIndex >= 0)
            {
                ListaDeCompras ListaDeCompra = (ListaDeCompras)this.ListaIngredientes_Mensual.SelectedItem;
                Ingrediente Modificar = HellCook.Business.Ingrediente_Buscador.ObtenerIngredientePorGodigo(ListaDeCompra.Codigo_Ingrediente.ToString());
                Ingrediente_Administrador.IngredientFunctionality.ModificarIngrediente modificar = new Ingrediente_Administrador.IngredientFunctionality.ModificarIngrediente(Modificar);
                modificar.ShowDialog();

                this.ListaIngredientes_Mensual.SelectedIndex = -1;
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void ActualizarListasDeCompras()
        {
            string FechaDeHoy = DateTime.Today.DayOfWeek.ToString();


            if (String.Equals(FechaDeHoy, "Sunday"))
            {
                this.Boton_MenuSemanal.IsEnabled = true;
                this.button_AdministrarMenuSemanal.IsEnabled = false;
            }
            else
            {
                this.Boton_MenuSemanal.IsEnabled = false;
            }

            this.ListaIngredientes_Diario.ItemsSource = HellCook.Business.ListaDeCompras_Acceso.ObtenerListaDiaria();
            if (this.ListaIngredientes_Diario.Items.Count > 0)
            {
                this.Button_ImprimirListaComprasDiarias.IsEnabled = true;
            }
            else
            {
                this.Button_ImprimirListaComprasDiarias.IsEnabled = false;
            }

            this.ListaIngredientes_Semanal.ItemsSource = HellCook.Business.ListaDeCompras_Acceso.ObtenerListaSemanal();
            if (this.ListaIngredientes_Semanal.Items.Count > 0)
            {
                this.Button_ImprimirListaComprasSemanal.IsEnabled = true;
            }
            else
            {
                this.Button_ImprimirListaComprasSemanal.IsEnabled = false;
            }

            this.ListaIngredientes_Mensual.ItemsSource = HellCook.Business.ListaDeCompras_Acceso.ObtenerListaMensual();
            if (this.ListaIngredientes_Mensual.Items.Count > 0)
            {
                this.Button_ImprimirListaComprasMensual.IsEnabled = true;
            }
            else
            {
                this.Button_ImprimirListaComprasMensual.IsEnabled = false;
            }
        }

        private void button_ActualizarListaDeCompras_Click(object sender, RoutedEventArgs e)
        {
            ActualizarListasDeCompras();
        }        
    }
}
